package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.comm.page.Page;
import com.zoo.diannaopeijian.comm.sql.GeneratorExampleBuilder;
import com.zoo.diannaopeijian.domain.Ware;
import com.zoo.diannaopeijian.domain.WareParameterDetail;
import com.zoo.diannaopeijian.domain.WareParameterDetailExample;
import com.zoo.diannaopeijian.mapper.WareParameterDetailMapper;
import com.zoo.diannaopeijian.service.WareComponentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by zx583 on 2018-01-18.
 */
@Service
public class WareComponentServiceImpl implements WareComponentService {
    @Resource
    private WareParameterDetailMapper wareParameterDetailMapper;


    @Override
    public boolean addWareComponent(WareParameterDetail wareParameterDetail) {
        return wareParameterDetailMapper.insertSelective(wareParameterDetail) == 1;
    }

    @Override
    public List<Map> getWareComponent(Integer wareid) {
        return wareParameterDetailMapper.getWareComponent(wareid);
    }

    @Override
    public boolean removeWareComponent(WareParameterDetail wareParameterDetail) {
        WareParameterDetailExample example = (WareParameterDetailExample) GeneratorExampleBuilder.buildEqualExample(WareParameterDetailExample.class, wareParameterDetail, false);

        if (example == null) {
            // 非法条件对象
            return false;
        }

        return wareParameterDetailMapper.deleteByExample(example) == 1;
    }

    @Override
    public List<Ware> getComponentWareWithPage(Ware ware, Page page, Integer componentid, Integer componentparameterdetailid) {
        page.onPage();

        return getComponentWare(ware, componentid, componentparameterdetailid);
    }

    @Override
    public List<Ware> getComponentWare(Ware ware, Integer componentid, Integer componentparameterdetailid) {
        return wareParameterDetailMapper.getComponentWare(ware, componentid, componentparameterdetailid);
    }

    @Override
    public List<Ware> getFuzzyComponentWareWithPage(Ware ware, Page page, Integer componentid, Integer componentparameterdetailid) {
        page.onPage();

        return getFuzzyComponentWare(ware, componentid, componentparameterdetailid);
    }

    @Override
    public List<Ware> getFuzzyComponentWare(Ware ware, Integer componentid, Integer componentparameterdetailid) {
        return wareParameterDetailMapper.getFuzzyComponentWare(ware, componentid, componentparameterdetailid);
    }
}
